package com.thiswhyme.fsplus.sentinel.feign.defaultdegrade;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.sentinel.SentinelProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @description: 兜底降级配置
 * @author: thiswhyme
 * @date: 2021/4/26
 */
@ConditionalOnProperty(name = "feign.sentinel.fsplus.base-degrade.enabled", havingValue = "true")
@EnableConfigurationProperties(BaseDegradeProperties.class)
public class BaseDegradeConfig {

    @Bean
    @ConditionalOnMissingBean(AutoBaseDegradeConfigHandler.class)
    public AutoBaseDegradeConfigHandler baseDegradeHandler(NacosDiscoveryProperties nacosDiscoveryProperties,
                                                           SentinelProperties sentinelProperties,
                                                           BaseDegradeProperties baseDegradeProperties) {
        return new AutoBaseDegradeConfigHandler(nacosDiscoveryProperties, sentinelProperties, baseDegradeProperties);
    }
}
